﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MeasureAbstract.IMotionDevice;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 紧缩场反射面装调测试系统.Controll
{
    /// <summary>
    /// CommunicationSelect.xaml 的交互逻辑
    /// </summary>
    [INotifyPropertyChanged]
    public partial class CommunicationSelect : UserControl
    {
        public CommunicationSelect()
        {
            InitializeComponent();
        }



        public string ID
        {
            get { return (string)GetValue(IDProperty); }
            set { SetValue(IDProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ID.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IDProperty =
            DependencyProperty.Register("ID", typeof(string), typeof(CommunicationSelect), new PropertyMetadata(""));



        public CommunicationConfig Config
        {
            get { return (CommunicationConfig)GetValue(ConfigProperty); }
            set { SetValue(ConfigProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Config.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ConfigProperty =
            DependencyProperty.Register("Config", typeof(CommunicationConfig), typeof(CommunicationSelect), new PropertyMetadata(null));

        [RelayCommand]
        public void SelectedChange()
        {
            if (Config.CommunicationList != null)
            {
                foreach (var temp in Config.CommunicationList)
                {
                    if (temp.Selected && temp.Support)
                    {
                        //MessageBox.Show($"选择了{temp.Name}");
                        switch (temp.Name)
                        {
                            case "TCP":
                                Config.ShowTCP = true;
                                Config.ShowUDP = false;
                                Config.ShowUART = false;
                                Config.ShowGPIB = false;
                                break;
                            case "UDP":
                                Config.ShowTCP = false;
                                Config.ShowUDP = true;
                                Config.ShowUART = false;
                                Config.ShowGPIB = false;
                                break;
                            case "UART":
                                Config.ShowTCP = false;
                                Config.ShowUDP = false;
                                Config.ShowUART = true;
                                Config.ShowGPIB = false;
                                break;
                            case "GPIB":
                                Config.ShowTCP = false;
                                Config.ShowUDP = false;
                                Config.ShowUART = false;
                                Config.ShowGPIB = true;
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
        }
        private void TreeViewItem_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)

        {

            e.Handled = true;

        }
    }
}
